package com.baikeyang.app.controller.api;

import com.alibaba.fastjson.JSON;
import com.baikeyang.common.netease.ApiUtil;
import com.baikeyang.common.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController(value = "musicController")
@RequestMapping
public class MusicController {


  @RequestMapping(value = "/api/music/v1/fm", method = RequestMethod.GET)
  public Object getFM() {
    String url = "/weapi/v1/radio/get";
    String str = "{\"csrf_token\":\"\"}";
    String result = ApiUtil.httpPost(url, str);
    return result;
  }
  /**
   * 获取歌单的详情
   * @return
   */
  @RequestMapping(value = "/api/music/v1/music/detail", method = RequestMethod.GET)
  public String getPalyListDetails(@RequestParam String id) {
    if(StringUtils.isNotEmpty(id)){id = "16034093";}
    Map<String, Object> param = new HashMap<String, Object>();
    param.put("id", id);
    Map<String, Object> c = new HashMap<String, Object>();
    c.put("id", id);
    param.put("c", JSON.toJSONString(c));
    param.put("ids", "[" + id + "]");
    param.put("csrf_token", "");

    String url = "/weapi/v3/song/detail";
    String str = "{\"csrf_token\":\"\"}";
    String result = ApiUtil.httpPost(url, JSON.toJSONString(param));
    System.out.println(result);
    return result;
  }

  ///weapi/v1/discovery/new/songs'
  @RequestMapping(value = "/api/music/v1/top/songs", method = RequestMethod.GET)
  public String getTopSongs() {
    Map<String, Object> param = new HashMap<String, Object>();
    param.put("type", "");
    param.put("area", "");
    param.put("cat", "");
    param.put("csrf_token", "");

    String url = "/weapi/v1/discovery/new/songs";
    String result = ApiUtil.httpPost(url, JSON.toJSONString(param));
    System.out.println(result);
    return result;
  }


  public static void main(String[] args) {
//    String url = "/weapi/v1/radio/get";
//    String str = "{\"csrf_token\":\"\"}";
//    String result = ApiUtil.httpPost(url, str);
//    System.out.println(result);

    String id = "16034093";
    Map<String, Object> param = new HashMap<String, Object>();
    param.put("id", id);
    List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
    Map<String, Object> c = new HashMap<String, Object>();
    c.put("id", id);
    mapList.add(c);
    param.put("c", JSON.toJSONString(mapList));
    param.put("ids", '[' + id + ']');
    param.put("csrf_token", "");
    System.out.println(JSON.toJSONString(param));

    //
    String url = "/weapi/v3/song/detail";
    String str = "{\"c\":\"{\"id\":\"16034093\"}\",'csrf_token':\"\",\"ids\":\"[16034093]\",\"id\":\"16034093\"}";
    str = JSON.toJSONString(param);
    String result = ApiUtil.httpPost(url, str);
    System.out.println(result);
  }


}
